//order.js
//获取下单后的个人列表
const app = getApp()

Page({
  data: {
    motto: 'Powered by @####',
    orderList:null
  },
  //事件处理函数
  bindViewTap: function () {
    wx.navigateTo({
      url: '../logs/logs'
    })
  },
  onLoad: function () {
    if (!wx.getStorageSync('reload') && wx.getStorageSync('orders')) {
        // 下单成功直接 跳转显示
      this.setData({
        orderList: wx.getStorageSync('orders')
      })
    } else {
      // 否则请求下单数据 ，可以做成本地存储式 ，减少请求    
      wx.request({
        url: '####',
        data: { 'sessionId': wx.getStorageSync('sessionid')},
        success: function (res) {
          if(res.data){
            wx.setStorageSync('orders', res.data)
          }
        }
      })
     }
  },
  onShow: function () {
    // Do something when page ready.
    var st = setInterval( () => {
      if (wx.getStorageSync('orders')){
        this.setData({
          orderList: wx.getStorageSync('orders')
        })

        clearInterval(st)
      }
    },50)
  },
  toggleDetail: function(e){
    this.data.orderList[e.currentTarget.dataset.id].show = !this.data.orderList[e.currentTarget.dataset.id].show

    this.setData({
      orderList: this.data.orderList
    })
  },
  bindCopy: function(e){
    wx.setClipboardData({
      data: e.currentTarget.dataset.rel,
      success: function (res) {
        wx.showToast({
          title: '复制成功',
          icon: 'success',
          duration: 600,
          mask: true
        })
      }
    })
  }
})
